package DataStructureAndAlgorithm.Tedukuri.排序;
import java.util.Scanner;
import java.util.Arrays;

/*
本题需要离散化，因为，如果直接用数组的下标来表示语言，会MLE
需要先离散化，之后用二分来加速检索

思路：

    先对科学家会的语言进行排序，之后就可以用二分的方法。
    对于每种电影的语言的检索，就可以在nlogn的复杂度内完成了

    此处的二分。主要用来求第一个大于/小于val的值的index


*/

public class AcWing_103 {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n + 1];
        for (int i = 1; i <= n; i++)a[i] = in.nextInt();
        int m = in.nextInt();
        int[] b = new int[m + 1];
        for (int i = 1; i <= m; i++)b[i] = in.nextInt();
        int[] c = new int[m + 1];
        for (int i = 1; i <= m; i++)c[i] = in.nextInt();
        Arrays.sort(a);

        int res = 0;
        int lagCount = 0;
        int txtCount = 0;
        for (int i = 1; i <= m; i++){
            int lagId = b[i];
            int left = getIndex(a,lagId,true);
            //如果找不到听得懂第i部电影的科学家，则直接跳过本次循环
            if (left == -1)continue;
            int right = getIndex(a,lagId,false);
            int curLagCount = right - left + 1;
            //如果当前听得懂第i部电影的人增多了，则更新
            if (curLagCount > lagCount){
                res = i;
                lagCount = curLagCount;
                int txtId = c[i];
                left = getIndex(a,txtId,true);
                right = getIndex(a,txtId,false);
                txtCount = left == -1 ? 0 : right - left + 1;
            }else if (curLagCount == lagCount){
                //如果很开心的人一样多，则要通过比较开心的人数来更新res
                int txtId = c[i];
                left = getIndex(a,txtId,true);
                right = getIndex(a,txtId,false);
                int curTxtCount = right - left + 1;
                //比较开心的人比之前多了。则更新res
                if (curTxtCount > txtCount){
                    res = i;
                    txtCount = curTxtCount;
                }
            }
        }

        System.out.print(res);

    }
    static int getIndex(int[] a,int val,boolean isLeft){
        int l = 0,r = a.length - 1;
        while (l < r){
            if (isLeft){
                int mid = l + r >> 1;
                if (a[mid] >= val){
                    r = mid;
                }else {
                    l = mid + 1;
                }
            }else {
                int mid = l + r + 1 >> 1;
                if (a[mid] <= val){
                    l = mid;
                }else {
                    r = mid - 1;
                }
            }
        }
        return a[l] == val ? l : -1;
    }
}
